[broadway] Combine window move and resize into one op
authorAlexander Larsson <alexl@redhat.com>
Tue, 12 Apr 2011 09:11:36 +0000 (11:11 +0200)
committerAlexander Larsson <alexl@redhat.com>
Tue, 12 Apr 2011 09:12:39 +0000 (11:12 +0200)
This way we avoid sending a configure event for the inbetween state
if we're resizeing and moving at the same time.

gdk/broadway/broadway-demo.c
gdk/broadway/broadway.c
gdk/broadway/broadway.h
gdk/broadway/broadway.js
gdk/broadway/gdkwindow-broadway.c

index 70c5ff97504728de9f78ed18ffb7d67711630aa2..0ce3081ecebe60ff4f560fa4030c5ca7378ae17a 100644 (file)
@@ -186,7 +186,7 @@ demo2 (BroadwayOutput *output)
          broadway_output_put_rgba (output, 0, 0, 0, 800, 600, 800*4,
                                    cairo_image_surface_get_data(old_surface));
        }
-      broadway_output_move_surface (output, 0, 100 + i, 100 + i);
+      broadway_output_move_resize_surface (output, 0, 1, 100 + i, 100 + i, 0, 0, 0);
 
       rects[0].x = 500;
       rects[0].y = 0;
index 493efb86e4b563f8b95d39bdfa3a6420a2ac4d1d..3917145bbcbf338fb97c51244dada8315dad66a0 100644 (file)
@@ -747,38 +747,42 @@ broadway_output_destroy_surface(BroadwayOutput *output,  int id)
   broadway_output_write (output, buf, sizeof (buf));
 }
 
-void
-broadway_output_move_surface(BroadwayOutput *output,  int id, int x, int y)
-{
-  char buf[HEADER_LEN + 9];
-  int p;
-
-  p = write_header (output, buf, 'm');
-
-  append_uint16 (id, buf, &p);
-  append_uint16 (x, buf, &p);
-  append_uint16 (y, buf, &p);
-
-  assert (p == sizeof (buf));
-
-  broadway_output_write (output, buf, sizeof (buf));
-}
 
 void
-broadway_output_resize_surface(BroadwayOutput *output,  int id, int w, int h)
+broadway_output_move_resize_surface (BroadwayOutput *output,
+                                    int             id,
+                                    gboolean        has_pos,
+                                    int             x,
+                                    int             y,
+                                    gboolean        has_size,
+                                    int             w,
+                                    int             h)
 {
-  char buf[HEADER_LEN + 9];
+  char buf[HEADER_LEN+3+1+6+6];
   int p;
+  int val;
 
-  p = write_header (output, buf, 'r');
+  if (!has_pos && !has_size)
+    return;
 
-  append_uint16 (id, buf, &p);
-  append_uint16 (w, buf, &p);
-  append_uint16 (h, buf, &p);
+  p = write_header (output, buf, 'm');
 
-  assert (p == sizeof (buf));
+  val = (!!has_pos) | ((!!has_size) << 1);
+  append_uint16 (id, buf, &p);
+  buf[p++] = val + '0';
+  if (has_pos)
+    {
+      append_uint16 (x, buf, &p);
+      append_uint16 (y, buf, &p);
+    }
+  if (has_size)
+    {
+      append_uint16 (w, buf, &p);
+      append_uint16 (h, buf, &p);
+    }
+  assert (p <= sizeof (buf));
 
-  broadway_output_write (output, buf, sizeof (buf));
+  broadway_output_write (output, buf, p);
 }
 
 void
index 86df4df41cedd4212cb98b8ea881acc1a6c1c963..fce53a30a6a9eeaf317e9047c46e70e88cba7180 100644 (file)
@@ -26,14 +26,14 @@ void            broadway_output_hide_surface    (BroadwayOutput *output,
                                                 int             id);
 void            broadway_output_destroy_surface (BroadwayOutput *output,
                                                 int             id);
-void            broadway_output_move_surface    (BroadwayOutput *output,
-                                                int             id,
-                                                int             x,
-                                                int             y);
-void            broadway_output_resize_surface  (BroadwayOutput *output,
-                                                int             id,
-                                                int             w,
-                                                int             h);
+void            broadway_output_move_resize_surface (BroadwayOutput *output,
+                                                    int             id,
+                                                    gboolean        has_pos,
+                                                    int             x,
+                                                    int             y,
+                                                    gboolean        has_size,
+                                                    int             w,
+                                                    int             h);
 void            broadway_output_set_transient_for (BroadwayOutput *output,
                                                   int             id,
                                                   int             parent_id);
index e7bf51302e0f6fb5235e7e289a5e11aa236d35a9..c5f202d25e3bb895d6cd9de4e04aeb490f26458a 100644 (file)
@@ -638,12 +638,21 @@ function cmdDeleteSurface(id)
     delete surfaces[id];
 }
 
-function cmdMoveSurface(id, x, y)
+function cmdMoveResizeSurface(id, has_pos, x, y, has_size, w, h)
 {
     var surface = surfaces[id];
-    surface.positioned = true;
-    surface.x = x;
-    surface.y = y;
+    if (has_pos) {
+       surface.positioned = true;
+       surface.x = x;
+       surface.y = y;
+    }
+    if (has_size) {
+       surface.width = w;
+       surface.height = h;
+    }
+
+    /* Flush any outstanding draw ops before (possibly) changing size */
+    flushSurface(surface);
 
     if (surface.visible) {
        if (surface.window) {
@@ -651,51 +660,39 @@ function cmdMoveSurface(id, x, y)
             * However this isn't *strictly* invalid, as any WM could have done whatever it
             * wanted with the positioning of the window.
             */
-           surface.window.moveTo(surface.x, surface.y);
+           if (has_pos)
+               surface.window.moveTo(surface.x, surface.y);
+           if (has_size)
+               resizeBrowserWindow(surface.window, w, h);
        } else {
-           var xOffset = surface.x;
-           var yOffset = surface.y;
+           if (has_size)
+               resizeCanvas(surface.canvas, w, h);
 
-           var transientToplevel = getTransientToplevel(surface);
-           if (transientToplevel) {
-               xOffset = surface.x - transientToplevel.x;
-               yOffset = surface.y - transientToplevel.y;
-           }
+           if (has_pos) {
+               var xOffset = surface.x;
+               var yOffset = surface.y;
 
-           var element = surface.canvas;
-           if (surface.frame) {
-               element = surface.frame;
-               var offset = getFrameOffset(surface);
-               xOffset -= offset.x;
-               yOffset -= offset.y;
-           }
+               var transientToplevel = getTransientToplevel(surface);
+               if (transientToplevel) {
+                   xOffset = surface.x - transientToplevel.x;
+                   yOffset = surface.y - transientToplevel.y;
+               }
 
-           element.style["left"] = xOffset + "px";
-           element.style["top"] = yOffset + "px";
-       }
-    }
+               var element = surface.canvas;
+               if (surface.frame) {
+                   element = surface.frame;
+                   var offset = getFrameOffset(surface);
+                   xOffset -= offset.x;
+                   yOffset -= offset.y;
+               }
 
-    if (surface.window) {
-       updateBrowserWindowGeometry(surface.window, true);
-    } else {
-       sendConfigureNotify(surface);
+               element.style["left"] = xOffset + "px";
+               element.style["top"] = yOffset + "px";
+           }
+       }
     }
-}
-
-function cmdResizeSurface(id, w, h)
-{
-    var surface = surfaces[id];
-
-    surface.width = w;
-    surface.height = h;
-
-    /* Flush any outstanding draw ops before changing size */
-    flushSurface(surface);
-
-    resizeCanvas(surface.canvas, w, h);
 
     if (surface.window) {
-       resizeBrowserWindow(surface.window, w, h);
        updateBrowserWindowGeometry(surface.window, true);
     } else {
        sendConfigureNotify(surface);
@@ -776,21 +773,22 @@ function handleCommands(cmdObj)
        case 'm': // Move a surface
            id = base64_16(cmd, i);
            i = i + 3;
-           x = base64_16(cmd, i);
-           i = i + 3;
-           y = base64_16(cmd, i);
-           i = i + 3;
-           cmdMoveSurface(id, x, y);
-           break;
-
-       case 'r': // Resize a surface
-           id = base64_16(cmd, i);
-           i = i + 3;
-           w = base64_16(cmd, i);
-           i = i + 3;
-           h = base64_16(cmd, i);
-           i = i + 3;
-           cmdResizeSurface(id, w, h);
+           var ops = cmd.charCodeAt(i++) - 48;
+           var has_pos = ops & 1;
+           if (has_pos) {
+               x = base64_16s(cmd, i);
+               i = i + 3;
+               y = base64_16s(cmd, i);
+               i = i + 3;
+           }
+           var has_size = ops & 2;
+           if (has_size) {
+               w = base64_16(cmd, i);
+               i = i + 3;
+               h = base64_16(cmd, i);
+               i = i + 3;
+           }
+           cmdMoveResizeSurface(id, has_pos, x, y, has_size, w, h);
            break;
 
        case 'i': // Put image data surface
index 34a1ae66314783b66ad056f26f4cdec499599211..6b0a71392e4ef0b4f0c77b471771cfda86fcfa61 100644 (file)
@@ -598,6 +598,7 @@ gdk_window_broadway_move_resize (GdkWindow *window,
   GdkWindowImplBroadway *impl = GDK_WINDOW_IMPL_BROADWAY (window->impl);
   GdkBroadwayDisplay *broadway_display;
   gboolean changed;
+  gboolean with_resize;
 
   changed = FALSE;
 
@@ -607,17 +608,12 @@ gdk_window_broadway_move_resize (GdkWindow *window,
       changed = TRUE;
       window->x = x;
       window->y = y;
-      if (broadway_display->output != NULL)
-       {
-         broadway_output_move_surface (broadway_display->output,
-                                       impl->id, x, y);
-         queue_dirty_flush (broadway_display);
-       }
     }
 
-
+  with_resize = FALSE;
   if (width > 0 || height > 0)
     {
+      with_resize = TRUE;
       if (width < 1)
        width = 1;
 
@@ -633,13 +629,6 @@ gdk_window_broadway_move_resize (GdkWindow *window,
          impl->dirty = TRUE;
          impl->last_synced = FALSE;
 
-         if (broadway_display->output != NULL)
-           {
-             broadway_output_resize_surface (broadway_display->output,
-                                             impl->id, width, height);
-             queue_dirty_flush (broadway_display);
-           }
-
          window->width = width;
          window->height = height;
          _gdk_broadway_window_resize_surface (window);
@@ -651,6 +640,15 @@ gdk_window_broadway_move_resize (GdkWindow *window,
       GdkEvent *event;
       GList *node;
 
+      if (broadway_display->output != NULL)
+       {
+         broadway_output_move_resize_surface (broadway_display->output,
+                                              impl->id,
+                                              with_move, window->x, window->y,
+                                              with_resize, window->width, window->height);
+         queue_dirty_flush (broadway_display);
+       }
+
       event = gdk_event_new (GDK_CONFIGURE);
       event->configure.window = g_object_ref (window);
       event->configure.x = window->x;